package com.example.studywords.utils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {
    public static Calendar calendar = Calendar.getInstance();

    public static String getCurrentDate(){
         return  (calendar.get(Calendar.MONTH)+1)+"-"+calendar.get(Calendar.DAY_OF_MONTH);
    }

    public static int dateBetweenToday(String lastStudyTime){
        String currentDate = getCurrentDate();
        DateFormat dateFormat = new SimpleDateFormat("MM-dd");
        int distance = 0;
        try {
            Date startDate = dateFormat.parse(lastStudyTime),
                    endDate = dateFormat.parse(currentDate);
            Date nextDate = startDate;
            while (nextDate.before(endDate)){
                calendar.setTime(startDate);
                calendar.add(Calendar.DATE,1);
                startDate = calendar.getTime();
                nextDate = startDate;
                distance++;
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return distance;
    }
}
